Skip to content

Conversation

@jsjgdh
Copy link
Contributor

@jsjgdh jsjgdh commented Feb 7, 2026

Closes #3261

@jsjgdh jsjgdh marked this pull request as ready for review February 9, 2026 18:51
let projection = ((end - start).angle_to(mouse - start)).cos() * start.distance(mouse) / start.distance(end);

if distance.abs() < SEGMENT_INSERTION_DISTANCE && (0. ..=1.).contains(&projection) {
if let Some(index) = gradient.clone().insert_stop(mouse, transform) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gradient.clone() is called twice and insert_stop is called twice. This can be simplified:

let mut new_gradient = gradient.clone();
if let Some(index) = new_gradient.insert_stop(mouse, transform) {
    responses.add(DocumentMessage::StartTransaction);
    transaction_started = true;

    let mut selected_gradient = SelectedGradient::new(new_gradient, layer, document);
    selected_gradient.dragging = GradientDragTarget::Step(index);
    // No offset when inserting a new stop, it should be exactly under the mouse
    selected_gradient.render_gradient(responses);
    tool_data.selected_gradient = Some(selected_gradient);
    dragging = true;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done .

@Keavon Keavon changed the title Gizmo Add snapping to ends of the gradient line Feb 13, 2026
@Keavon
Copy link
Member

Keavon commented Feb 13, 2026

This kind of snapping doesn't actually snap:

capture_10_.mp4

It would need to calculate the color stop position where the gradient line intersects the snapping target line and snap it to that position when the snap is active, since the whole point of a snap is to take the precise mouse movements surrounding a target and jump them all to the exact value.

This also occurs when dragging an endpoint when Shift is held to snap to a 15° angle increment. Note that the Line tool's implementation of this same behavior does work as expected when you're dragging a line's endpoint and holding Shift or Ctrl to lock the angle:

capture_11_.mp4

The snapping tolerance for this scenario is more sane in the Line tool (smaller tolerance area) than it is for the Gradient tool (too large of a tolerance area, should match Line tool's behavior).

This is something I'm willing to wait on for a followup PR, if you prefer.

@Keavon Keavon marked this pull request as draft February 13, 2026 00:58
@Keavon Keavon mentioned this pull request Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Snapping for Gradient gizmo

3 participants